package org.syncsoft.overalt.core.api;

import java.util.Collection;
import java.util.HashSet;

import org.syncsoft.overalt.common.api.IObserver;

/**
 * concrete class that implements ICore
 * it's implements the singleton pattern
 * 
 * @author tptfc
 *
 */
public final class Core implements ICore {
	private final static Core instance;
	private Collection<IObserver> observers;

	static {
		instance = new Core();
	}
	
	private Core() {
		setObservers(new HashSet<IObserver>());
	}
	
	/**
	 * @return a unique and valid instance of Core class
	 */
	public static Core getInstance() {
		return instance;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.syncsoft.common.api.ISubject#addObserver(org.syncsoft.common.api.IObserver)
	 */
	@Override
	public void addObserver(IObserver observer) {
		if (observer != null) {
			getObservers().add(observer);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.syncsoft.common.api.ISubject#remObserver(org.syncsoft.common.api.IObserver)
	 */
	@Override
	public void remObserver(IObserver observer) {
		if (observer != null) {
			getObservers().remove(observer);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.syncsoft.common.api.ISubject#notifyAllObservers()
	 */
	@Override
	public void notifyAllObservers() {
		for (IObserver observer: getObservers()) {
			observer.updateObserver();
		}
	}
	
	//	GETS AND SETS
	private Collection<IObserver> getObservers() {
		return observers;
	}
	private void setObservers(Collection<IObserver> observers) {
		this.observers = observers;
	}

	@Override
	public void add(String path) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void commit(String path) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(String path) {
		// TODO Auto-generated method stub
		
	}
}
